/**
 * 队列性质的ui管理器
 */
import LayerManager from "./LayerManager"
import LayerInfo from "./LayerInfo"
import BaseView from "../base/view/BaseView";
class QueueLayerManager extends LayerManager {

    //添加layer
    pushView(layerInfo:LayerInfo){
        this.list.push(layerInfo);
        this.list.sort((a,b) =>{
            return a.getPriority() - b.getPriority();
        })
        if(this.list.length === 0){
            this.show(layerInfo);
        }
    }

    show(layerInfo:LayerInfo){
        this.root.addChild(layerInfo.getNode());    
    }
    // 移除layer
    popView(view:BaseView): boolean{
        if(!view){
            if(this.list.length > 0){
                let layerInfo = this.list.shift();     
                layerInfo.destroy();
                if(this.list.length > 0){
                    this.show(this.list.slice(0,1)[0]);
                }            
                return true;
            }else{
                return false;
            }
        }else{
            return this.removeView(view);
        }


    }


}
export = QueueLayerManager
